<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script type="text/javascript">
        function foo() {
            return new Promise(function(resolve, reject) {
                setTimeout(function() {
                    resolve(123)
                }, 1000);
            })
        }
        foo()
            .then(function(data) {
                console.log(data); //用于处理正常的结果
            })
            .catch(function(data) {
                console.log(data); //用来接收resolve传递过来的信息 获取异常信息
            })
            .finally(function() {
                console.log('finished'); //成功与否都会成功
            })
    </script>
</body>

</html>